#create Figure A2 in "Editor's Choice: Measuring Candidate Quality using Local Newspaper Endorsements"
#Journal of Politics, 2025
#Kevin DeLuca

library(readxl)
library(tidyverse)
library(tigris)

#set main folder path here:
#setwd("")

cty <- read_xlsx("countiesforA2.xlsx")

cty$fipscode <- str_pad(cty$fipscode, width = 5, side = "left", pad = "0")

county_sf <- tigris::counties()
states_sf <- tigris::states()

county_sf <- shift_geometry(county_sf)

states_sf <- states_sf %>%
  filter(!(STATEFP %in% c("02", "15"))) %>% 
  filter(!(NAME %in% c("United States Virgin Islands",
                       "Commonwealth of the Northern Mariana Islands",
                       "Guam",
                       "American Samoa",
                       "Puerto Rico")))

p <- county_sf %>%
  filter(!(STATEFP %in% c("02", "15", "72",
                          "78", "60", "66", "69"))) %>% 
  mutate(hl = GEOID %in% cty$fipscode) %>% 
  ggplot(aes(fill = hl)) +
  geom_sf(lwd = 0.2) +
  geom_sf(data = states_sf,
          fill = NA, color = "#372E39") +
  ggthemes::theme_map() +
  scale_fill_manual(values = c("grey", "darkblue")) +
  guides(fill = "none")
ggsave("results/figures/figureA2.pdf", p, width = 6.5, height = 4)
